#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	while (n--)
	{
		int m, n, k;
		int x;
		int flag1 = 0;
		int flag2 = 0;
		int flag = 1;
		scanf("%d %d %d", &m, &n, &k);
		int k2 = k / 2;
		int  arr[40000] = { 0 };
		int j = 2*k;
		while (m--)
		{
			int c;
			scanf("%d", &c);
			x = c;
			if (x<=k)
			{
				if (arr[x - 1] == 0)
				{
					arr[x - 1]++;
					j--;
					flag1++;
				}
			}
		}
		int flag3 = 0;
		flag2 = k2;
		int flag4 = 0;
		while (n--)
		{
			int c;
			scanf("%d", &c);
			x = c;
			if (x <= k)
			{
				if (arr[x - 1] == 0)
				{
					flag2--;
					j -= 2;
					arr[x - 1] = 2;
					flag4++;
				}
				if (arr[x - 1] == 1)
				{
					arr[x - 1] = 2;
					j--;
					flag3++;
					flag4++;
				}
			}
		}int ct = flag1 - flag3;
		j = j - ct ;

		if (flag4<k2||flag1<k2||flag2 < 0||j>0)
			flag = 0;
		if (flag)
			printf("YES\n");
		else
			printf("NO\n");
	}
}